#!/usr/local/python/bin/python
# coding=utf-8
__author__ = 'Junjie.M'

import os
import commands
import subprocess

from tdtools import LogUtil

_logger=LogUtil._logger
class ShellUtil(object):
    @staticmethod
    def execShell(shell_command):
        try:
            output = subprocess.check_output(shell_command, shell=True, stderr=subprocess.STDOUT, universal_newlines=True)
            _logger.info(output)
            return True
        except subprocess.CalledProcessError as e:
            _logger.error(e.output)
            return False

    # 执行shell命令
    # return status
    @staticmethod
    def exShell1(shellCommand):
        global logger
        status = os.system(shellCommand)
        if status == 0:
            return True
        else:
            return False



    # 执行shell命令
    # return (status,output)
    @staticmethod
    def exShell2(shellCommand):
        return commands.getstatusoutput(shellCommand)
